package BiTree;

/**
 * @program: java_concurrent
 * @description: 树是否对称
 * @author: lxf
 * @create: 2024-06-25 11:24
 **/
public class IsSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        return isSymmetric2(root.left,root.right);
    }

    private boolean isSymmetric2(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        if (left.val != right.val) return false;
        return isSymmetric2(left.left,right.right) && isSymmetric2(left.right,right.left);
    }
}
